package de.breitbeil.samsyncro.lib.domain.parser;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import de.breitbeil.samsyncro.lib.domain.fs.SFolder;

public class SFolderParser {

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd HH:mm:ss");
    
    public static ArrayList<SFolder> parseList(String s) {
        ArrayList<SFolder> folders = new ArrayList<SFolder>();
        String[] splitted = s.split("\\\\r\\\\n");
        for(String folder: splitted) {
            folders.add( parse(folder) );
        }
        return folders;
    }
    
    public static SFolder parse(String parse) {
        try {
            String[] splitted = parse.split(",");
            String name = splitted[0];
            String unknown1 = splitted[1];
            String unknown2 = splitted[2];
            Date created = sdf.parse(splitted[3]);
            
            SFolder sFolder = new SFolder();
            sFolder.setName(name);
            sFolder.setCreated(created);
            
            return sFolder;
        }
        catch(Exception e) {
            throw new IllegalArgumentException("Cant parse folder String: "+parse, e);
        }
    }
}
